<template>
    <a-spin :spinning="confirmLoading">
        <a-tabs :activeKey="labelPageKey" @change="handleTabBeforeChange">
            <a-tab-pane tab="进出厂车辆" key="tab1" :forceRender="true">
                <j-form-container :disabled="formDisabled">
                    <!-- 子标签页 -->
                    <a-form :form="form" slot="detail">
                        <a-row>
                            <a-col :span="24">
                                <a-form-item label="报到位置" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['locatin']" :disabled="true"
                                        placeholder="请输入报到位置"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="司机姓名" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['driverName', validatorRules.driverName]"
                                        placeholder="请输入司机姓名"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="身份证号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['idCard', validatorRules.idCard]"
                                        placeholder="请输入身份证号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="手机号码" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['phoneNum', validatorRules.phoneNum]"
                                        placeholder="请输入手机号码"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="车牌颜色" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list"
                                        v-decorator="['plateColor', validatorRules.plateColor]"
                                        :trigger-change="true" dictCode="cpys"
                                        placeholder="请选择车牌颜色" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="车牌号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['plateNo', validatorRules.plateNo]"
                                        placeholder="请输入车牌号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="车辆类型" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list"
                                        v-decorator="['carType', validatorRules.carType]"
                                        :trigger-change="true" dictCode="cllx"
                                        placeholder="请选择车辆类型" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="车辆品牌型号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['carBrandModel']"
                                        placeholder="请输入车辆品牌型号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="燃料类型" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list" v-decorator="['fuelType']"
                                        :trigger-change="true" dictCode="fuel_type"
                                        placeholder="请选择燃料类型" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="排放类型" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list"
                                        v-decorator="['evnType', validatorRules.evnType]"
                                        :trigger-change="true" dictCode="pflx"
                                        placeholder="请选择排放类型" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="联网状态" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list"
                                        v-decorator="['networkingStatus']" :trigger-change="true"
                                        dictCode="networking_status" placeholder="请选择联网状态" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="使用性质" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list" v-decorator="['function']"
                                        :trigger-change="true" dictCode="function"
                                        placeholder="请选择使用性质" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="VIN识别码" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['vin']"
                                        placeholder="请输入VIN识别码"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="发动机号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['engineNum']"
                                        placeholder="请输入发动机号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="注册日期" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-date placeholder="请选择注册日期" v-decorator="['registerDate']"
                                        :trigger-change="true" style="width: 100%" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="所属车队" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['fleet']"
                                        placeholder="请输入所属车队"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="运输状态" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list"
                                        v-decorator="['networkingStatus']" :trigger-change="true"
                                        dictCode="yslx" placeholder="请选择运输状态" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="运输内容" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['goods']"
                                        placeholder="请输入运输内容"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="运输量（吨）" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['freightVolume']"
                                        placeholder="请输入运输量"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="行驶证" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-image-upload isMultiple
                                        v-decorator="['lisense']"></j-image-upload>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="环保清单" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-image-upload isMultiple
                                        v-decorator="['inventory']"></j-image-upload>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="登记状态" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list" v-decorator="['statusLedger']"
                                        :trigger-change="true" dictCode="tzzt"
                                        placeholder="请选择登记状态" />
                                </a-form-item>
                            </a-col>
                            <a-col v-if="showFlowSubmitButton" :span="24"
                                style="text-align: center">
                                <a-button @click="submitForm">提 交</a-button>
                            </a-col>
                        </a-row>
                    </a-form>
                </j-form-container>
            </a-tab-pane>
            <a-tab-pane tab="厂内运输车辆" key="tab2" :forceRender="true">
                <j-form-container :disabled="formDisabled">
                    <a-form :form="form" slot="detail">
                        <a-row>
                            <a-col :span="24">
                                <a-form-item label="报到位置" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['locatin']" :disabled="true"
                                        placeholder="请输入报到位置"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="司机姓名" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['driverName', validatorRules.driverName]"
                                        placeholder="请输入司机姓名"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="身份证号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['idCard', validatorRules.idCard]"
                                        placeholder="请输入身份证号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="手机号码" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['phoneNum', validatorRules.phoneNum]"
                                        placeholder="请输入手机号码"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="环保登记编码" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['registrationCode']"
                                        placeholder="请输入环保登记编码"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="VIN识别码" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['vin']"
                                        placeholder="请输入VIN识别码"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="生产日期" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-date placeholder="请选择生产日期" v-decorator="['producedTime']"
                                        :trigger-change="true" style="width: 100%" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="车牌颜色" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list"
                                        v-decorator="['plateColor', validatorRules.plateColor]"
                                        :trigger-change="true" dictCode="cpys"
                                        placeholder="请选择车牌颜色" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="车牌号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['plateNo', validatorRules.plateNo]"
                                        placeholder="请输入车牌号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="注册登记日期" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-date placeholder="请选择注册登记日期" v-decorator="['registerDate']"
                                        :trigger-change="true" style="width: 100%" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="车辆品牌型号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['carBrandModel']"
                                        placeholder="请输入车辆品牌型号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="燃料类型" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list" v-decorator="['fuelType']"
                                        :trigger-change="true" dictCode="fuel_type"
                                        placeholder="请选择燃料类型" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="排放类型" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list"
                                        v-decorator="['evnType', validatorRules.evnType]"
                                        :trigger-change="true" dictCode="pflx"
                                        placeholder="请选择排放类型" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="联网状态" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list"
                                        v-decorator="['networkingStatus']" :trigger-change="true"
                                        dictCode="networking_status" placeholder="请选择联网状态" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="行驶证" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-image-upload isMultiple
                                        v-decorator="['lisense']"></j-image-upload>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="环保清单" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-image-upload isMultiple
                                        v-decorator="['inventory']"></j-image-upload>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="车辆所有人(单位)" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['vehicleOwner']"
                                        placeholder="请输入车辆所有人(单位)"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col v-if="showFlowSubmitButton" :span="24"
                                style="text-align: center">
                                <a-button @click="submitForm">提 交</a-button>
                            </a-col>
                        </a-row>
                    </a-form>
                </j-form-container>
            </a-tab-pane>
            <a-tab-pane tab="非道路移动机械" key="tab3" :forceRender="true">
                <j-form-container :disabled="formDisabled">
                    <a-form :form="form" slot="detail">
                        <a-row>
                            <a-col :span="24">
                                <a-form-item label="报到位置" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['locatin']" :disabled="true"
                                        placeholder="请输入报到位置"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="司机姓名" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['driverName', validatorRules.driverName]"
                                        placeholder="请输入司机姓名"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="身份证号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['idCard', validatorRules.idCard]"
                                        placeholder="请输入身份证号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="手机号码" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['phoneNum', validatorRules.phoneNum]"
                                        placeholder="请输入手机号码"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="环保登记编码" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['registrationCode']"
                                        placeholder="请输入环保登记编码"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="生产日期" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-date placeholder="请选择生产日期" v-decorator="['producedTime']"
                                        :trigger-change="true" style="width: 100%" />
                                </a-form-item>
                            </a-col>
                            <!-- <a-col :span="24">
                <a-form-item label="车牌颜色" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <j-dict-select-tag type="list" v-decorator="['plateColor', validatorRules.plateColor]"
                    :trigger-change="true" dictCode="cpys" placeholder="请选择车牌颜色" />
                </a-form-item>
              </a-col>
              <a-col :span="24">
                <a-form-item label="车牌号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['plateNo', validatorRules.plateNo]" placeholder="请输入车牌号"></a-input>
                </a-form-item>
              </a-col> -->
                            <a-col :span="24">
                                <a-form-item label="排放类型" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list"
                                        v-decorator="['evnType', validatorRules.evnType]"
                                        :trigger-change="true" dictCode="pflx"
                                        placeholder="请选择排放类型" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="燃料类型" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list" v-decorator="['fuelType']"
                                        :trigger-change="true" dictCode="fuel_type"
                                        placeholder="请选择燃料类型" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="车辆类型" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-dict-select-tag type="list"
                                        v-decorator="['carType', validatorRules.carType]"
                                        :trigger-change="true" dictCode="machinery_type"
                                        placeholder="请选择车辆类型" />
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="机械环保代码/产品识别码(PIN)" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['pin']"
                                        placeholder="请输入机械环保代码/产品识别码(PIN)"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="机械型号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['mechanicalModel']"
                                        placeholder="请输入机械型号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="发动机型号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['engineModel']"
                                        placeholder="请输入发动机型号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="发动机生产商" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['engineProducer']"
                                        placeholder="请输入发动机生产商"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="发动机号" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['engineNum']"
                                        placeholder="请输入发动机号"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="整车(机)铭牌" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-image-upload isMultiple
                                        v-decorator="['machineNameplate']"></j-image-upload>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="发动机铭牌" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-image-upload isMultiple
                                        v-decorator="['engineNameplate']"></j-image-upload>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="机械环保信息标签" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <j-image-upload isMultiple
                                        v-decorator="['machineLabel']"></j-image-upload>
                                </a-form-item>
                            </a-col>
                            <a-col :span="24">
                                <a-form-item label="所属人" :labelCol="labelCol"
                                    :wrapperCol="wrapperCol">
                                    <a-input v-decorator="['vehicleOwner']"
                                        placeholder="请输入车辆所有人"></a-input>
                                </a-form-item>
                            </a-col>
                            <a-col v-if="showFlowSubmitButton" :span="24"
                                style="text-align: center">
                                <a-button @click="submitForm">提 交</a-button>
                            </a-col>
                        </a-row>
                    </a-form>
                </j-form-container>
            </a-tab-pane>
        </a-tabs>
        <!-- <a-row v-if="showFlowSubmitButton" style="text-align: center;width: 100%;margin-top: 16px;"><a-button
        @click="submitForm">提 交</a-button></a-row> -->
    </a-spin>
</template>

<script>

import { httpAction, getAction, postAction } from '@/api/manage'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'

export default {
    name: 'CarRegisterForm',
    components: {
    },
    props: {
        //流程表单data
        formData: {
            type: Object,
            default: () => { },
            required: false
        },
        //表单模式：true流程表单 false普通表单
        formBpm: {
            type: Boolean,
            default: false,
            required: false
        },
        //表单禁用
        disabled: {
            type: Boolean,
            default: false,
            required: false
        }
    },
    data() {
        return {
            labelPageKey: '',//当前标签页
            form: this.$form.createForm(this),
            model: {},
            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 },
            },
            confirmLoading: false,
            validatorRules: {
                // locatin: {
                //   rules: [
                //     { required: true, message: '请输入报到位置!' },
                //   ]
                // },
                driverName: {
                    rules: [
                        { required: true, message: '请输入司机姓名!' },
                    ]
                },
                idCard: {
                    rules: [
                        { required: true, message: '请输入身份证号!' },
                        {
                            pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
                            message: '身份证号格式不正确'
                        }
                    ]
                },
                phoneNum: {
                    rules: [
                        { required: true, message: '请输入手机号码!' },
                        { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!' },
                    ]
                },
                plateColor: {
                    rules: [
                        { required: true, message: '请输入车牌颜色!' },
                    ]
                },
                plateNo: {
                    rules: [
                        { required: true, message: '请输入车牌号!' },
                    ]
                },
                carType: {
                    rules: [
                        { required: true, message: '请输入车辆类型!' },
                    ]
                },
                evnType: {
                    rules: [
                        { required: true, message: '请输入排放类型!' },
                    ]
                },
                // vin: {
                //   rules: [
                //     { required: true, message: '请输入VIN识别码!' },
                //   ]
                // },
                // engineNum: {
                //   rules: [
                //     { required: true, message: '请输入发动机号!' },
                //   ]
                // },
                // registerDate: {
                //   rules: [
                //     { required: true, message: '请输入注册日期!' },
                //   ]
                // },
                // fleet: {
                //   rules: [
                //     { required: true, message: '请输入所属车队!' },
                //   ]
                // },
                // goods: {
                //   rules: [
                //     { required: true, message: '请输入运输内容!' },
                //   ]
                // },
                // lisense: {
                //   rules: [
                //     { required: true, message: '请输入行驶证!' },
                //   ]
                // },
                // inventory: {
                //   rules: [
                //     { required: true, message: '请输入环保清单!' },
                //   ]
                // },
            },
            url: {
                add: "/carinfo/carRegister/add",
                edit: "/carinfo/carRegister/edit",
                queryById: "/carinfo/carRegister/queryById",
                getCompanyName: "/enterpriseBasicInformation/enterpriseBasicInformation/getEnterpriseName",
                upload: "/carinfo/carRegister/upload",
            },
            locatin: "",
        }
    },
    computed: {
        formDisabled() {
            if (this.formBpm === true) {
                if (this.formData.disabled === false) {
                    return false
                }
                return true
            }
            return this.disabled
        },
        showFlowSubmitButton() {
            if (this.formBpm === true) {
                if (this.formData.disabled === false) {
                    return true
                }
            }
            return false
        }
    },
    created() {
        //如果是流程中表单，则需要加载流程表单data
        this.showFlowData();
        this.getCompanyName();
    },
    methods: {
        // 自定义上传方法
        // customUploadAction(file) {
        //   const data = {
        //     file: file,
        //   };
        //   postAction(this.url.upload, file).then((res) => {
        //     if (res.result.success) {
        //       this.model.machineLabel = res.result.message;
        //     } else {
        //       that.$message.error(res.result.message);
        //     }
        //   }).catch((error) => {
        //     console.log(error);
        //   });
        // },
        // 获取企业名称
        getCompanyName() {
            getAction(this.url.getCompanyName).then((res) => {
                this.locatin = res.result;
            }).catch((error) => {
                console.log(error);
            })
        },
        // 标签页切换调用
        handleTabBeforeChange(value) {
            if (this.form && !this.form.isFieldsTouched()) {
                // 获取表单所有字段的值
                const fieldsValue = this.form.getFieldsValue();
                // 判断表单是否有值
                if (Object.values(fieldsValue).some(value => value !== undefined && value !== '')) {
                    // 表单有值，禁止切换标签
                    return false;
                }
                // 表单未修改且无值，允许切换标签
                this.labelPageKey = value;
                return true;
            } else {
                // 表单已修改，禁止直接切换标签
                var result = confirm("切换标签会清空已有数据 , 是否继续?");
                if (result) {
                    // 用户点击了确定按钮
                    this.form.resetFields();
                    this.labelPageKey = value;
                    return true;
                } else {
                    // 用户点击了取消按钮
                    return false;
                }
            }
        },
        add() {
            this.edit({});
        },
        edit(record) {
            console.log(record.lisense)
            this.form.resetFields();
            this.model = Object.assign({}, record);
            this.visible = true;
            this.$nextTick(() => {
                this.form.setFieldsValue(pick(this.model, 'locatin', 'driverName', 'idCard', 'phoneNum', 'plateColor', 'plateNo', 'carType', 'evnType', 'vin', 'engineNum', 'registerDate', 'fleet', 'goods', 'lisense', 'inventory', 'status', 'statusLedger', 'freightVolume', 'function', 'fuelType', 'carBrandModel', 'networkingStatus', 'transportGoodsName', 'mechanicalModel', 'engineModel', 'pin', 'vehicleOwner', 'machineNameplate', 'producedTime', 'engineProducer', 'registrationCode', 'machineLabel', 'engineNameplate', 'carSort'))
                if (this.model.carSort === 1) {
                    this.labelPageKey = 'tab2';
                } else if (this.model.carSort === 2) {
                    this.labelPageKey = 'tab3';
                } else {
                    this.labelPageKey = 'tab1';
                }
            })
        },
        //渲染流程表单数据
        showFlowData() {
            if (this.formBpm === true) {
                let params = { id: this.formData.dataId };
                getAction(this.url.queryById, params).then((res) => {
                    if (res.success) {
                        this.edit(res.result);
                    }
                });
            }
        },
        submitForm() {
            // this.getCompanyName();
            if (this.labelPageKey == 'tab1') {
                this.model.carSort = 0;
            } else if (this.labelPageKey == 'tab2') {
                this.model.carSort = 1;
            } else {
                this.model.carSort = 2;
            }
            // this.model.locatin = this.locatin;
            this.form.setFieldsValue({
                'locatin': this.locatin
            });
            const that = this;
            // 触发表单验证
            this.form.validateFields((err, values) => {
                if (!err) {
                    that.confirmLoading = true;
                    let httpurl = '';
                    let method = '';
                    if (!this.model.id) {
                        httpurl += this.url.add;
                        method = 'post';
                    } else {
                        httpurl += this.url.edit;
                        method = 'put';
                    }
                    let formData = Object.assign(this.model, values);
                    console.log("表单提交数据", formData)
                    httpAction(httpurl, formData, method).then((res) => {
                        if (res.success) {
                            that.$message.success(res.message);
                            that.$emit('ok');
                        } else {
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                    })
                }

            })
        },
        popupCallback(row) {
            this.form.setFieldsValue(pick(row, 'locatin', 'driverName', 'idCard', 'phoneNum', 'plateColor', 'plateNo', 'carType', 'evnType', 'vin', 'engineNum', 'registerDate', 'fleet', 'goods', 'lisense', 'inventory', 'status', 'statusLedger', 'freightVolume', 'function', 'fuelType', 'carBrandModel', 'networkingStatus', 'transportGoodsName', 'mechanicalModel', 'engineModel', 'pin', 'vehicleOwner', 'machineNameplate', 'producedTime', 'engineProducer', 'registrationCode', 'machineLabel', 'engineNameplate', 'carSort'))
        },
    }
}
</script>